//
//  FanstrdNormalCell.m
//  LiveStar
//
//  Created by 漪珊 on 2017/2/13.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "FanstrdNormalCell.h"
#import "FansTrdFrameModel.h"
#import "FansTrdModel.h"
#import "YBPictureView.h"
#import "TrendBottomView.h"

@implementation FanstrdNormalCell

- (void)prepareForReuse {
    [super prepareForReuse];
//    [self.picturesView.pictures removeAllObjects];
    //控件或控件内容置空
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}

- (UIImageView *)iconimgView {
    if (!_iconimgView) {
        _iconimgView = [[UIImageView alloc] init];
        kImageViewRadius(_iconimgView, 35*kScale/2);
    }
    return _iconimgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = UIFont(14);
    }
    return _nameLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.textColor = HESHEX_COLOR(@"999999");
        _timeLabel.font = UIFont(12);
    }
    return _timeLabel;
}

- (UIButton *)liveStatusBtn {
    if (!_liveStatusBtn) {
        _liveStatusBtn = [[UIButton alloc] init];
    }
    return _liveStatusBtn;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.numberOfLines = 0;
        _contentLabel.textColor = HESHEX_COLOR(@"666666");
        _contentLabel.font = UIFont(14);
    }
    return _contentLabel;
}

- (YBPictureView *)picturesView {
    if (!_picturesView) {
        _picturesView = [[YBPictureView alloc] init];
    }
    return _picturesView;
}

- (TrendBottomView *)toolView {
    if (!_toolView) {
        _toolView = [[TrendBottomView alloc] init];
        [_toolView.likeBtn addTarget:self action:@selector(praised:) forControlEvents:UIControlEventTouchUpInside];
        [_toolView.commentBtn addTarget:self action:@selector(praised:) forControlEvents:UIControlEventTouchUpInside];
        [_toolView.shareBtn addTarget:self action:@selector(praised:) forControlEvents:UIControlEventTouchUpInside];
        _toolView.backgroundColor = [UIColor whiteColor];
    }
    return _toolView;
}

- (UIView *)sepline {
    if (!_sepline) {
        _sepline = [[UIView alloc] init];
        _sepline.backgroundColor = [UIColor cellLineColor];
    }
    return _sepline;
}

- (void)setUpUI {
    //iconImgView
    [self addSubview:self.iconimgView];
    [self.iconimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(17);
        make.left.equalTo(self.mas_left).offset(12);
        make.height.width.mas_equalTo(35*kScale);
    }];
    
    //nameLabel
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconimgView.mas_top);
        make.left.mas_equalTo(self.iconimgView.mas_right).offset(5);
    }];
    
    //timeLabel
    [self addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.iconimgView.mas_bottom);
        make.left.mas_equalTo(self.iconimgView.mas_right).offset(5);
    }];
    
    //liveStatusBtn
    [self addSubview:self.liveStatusBtn];
    [self.liveStatusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconimgView.mas_centerY);
        make.right.mas_equalTo(self.iconimgView.mas_right).offset(-12);
    }];
    
    //contentLabel
    [self addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.iconimgView.mas_bottom).offset(15);
        make.leading.mas_equalTo(self.timeLabel.mas_leading);
        make.right.mas_equalTo(self.mas_right).offset(-12);
    }];
    
    //picturesView
    [self addSubview:self.picturesView];
    [self.picturesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(15);
        make.leading.mas_equalTo(self.timeLabel.mas_leading);
        make.right.mas_equalTo(self.mas_right).offset(-12);
        make.height.mas_equalTo(self.frameModel.picViewHeight);
    }];
    
    //toolView
    [self addSubview:self.toolView];
    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.picturesView.mas_bottom).offset(10);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(44);
    }];
    
    //sepline
    [self addSubview:self.sepline];
    [self.sepline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.toolView.mas_bottom);
        make.left.right.mas_equalTo(self);
        make.height.mas_equalTo(5);
    }];
}
- (void)setFrameModel:(FansTrdFrameModel *)frameModel {
    _frameModel = frameModel;
    FansTrdModel *model = frameModel.trendModel;
    self.picturesView.pictures = model.pictureArray;
    [self.picturesView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(frameModel.picViewHeight);
    }];
    self.contentLabel.text = model.c_content;
    [self.iconimgView sd_setImageWithURL:[NSURL URLWithString:model.u_avatar] placeholderImage:kPlACE_ICON];
    self.timeLabel.text = model.c_createtime;
    self.nameLabel.text = model.u_nickname;
    [self.toolView.likeBtn setTitle:KString(model.c_like) forState:UIControlStateNormal];
    [self.toolView.commentBtn setTitle:KString(model.c_comment) forState:UIControlStateNormal];
    [self.toolView.shareBtn setTitle:KString(model.c_share) forState:UIControlStateNormal];
    if ([model.booked intValue] == 10) {//已赞
        [self.toolView.likeBtn setImage:kSET_IMAGE(@"praise_selected") forState:UIControlStateNormal];
    } else {
        [self.toolView.likeBtn setImage:kSET_IMAGE(@"praise_normal") forState:UIControlStateNormal];
    }
}
#pragma mark -- 点赞
- (void)praised:(id)sender {
    if (sender == self.toolView.likeBtn) {
        [self.delegate praiseClickwithCell:self Tag:0];
    } else if (sender == self.toolView.commentBtn) {
        [self.delegate praiseClickwithCell:self Tag:1];
    } else {
        [self.delegate praiseClickwithCell:self Tag:2];
    }
}

@end
